package com.dap.configsvrclient.util;

import org.springframework.util.Assert;

import com.dap.core.config.BootstrapConfigUtil;


public class ConfigSvrConfig {
    private static final ConfigSvrConfig instance = new ConfigSvrConfig();
    private String configSvrHost;
    private String appName;
    private String version;
    private String env;
    private boolean isEnable = false;


    private ConfigSvrConfig() {
        this.configSvrHost = BootstrapConfigUtil.getProperty(BootstrapConfigUtil.CONFIG_SERVER_HOST);
        String enable = BootstrapConfigUtil.getProperty(BootstrapConfigUtil.CONFIG_SERVER_ENABLE);
        if ("true".equals(enable)) {
            this.isEnable = true;
        }
        this.appName = BootstrapConfigUtil.getProperty(BootstrapConfigUtil.APP_NAME);
        this.version = BootstrapConfigUtil.getProperty(BootstrapConfigUtil.APP_VERSION);
        this.env = BootstrapConfigUtil.getProperty(BootstrapConfigUtil.APP_ENV);
        Assert.notNull(this.configSvrHost);
        Assert.notNull(this.appName);
        Assert.notNull(this.version);
        Assert.notNull(this.env);
        this.configSvrHost = this.configSvrHost.trim();
        if (this.configSvrHost.indexOf("://") == -1) {
            this.configSvrHost = ("http://" + this.configSvrHost);
        }
        if ((this.configSvrHost.endsWith("/")) || (this.configSvrHost.endsWith("\\"))) {
            this.configSvrHost = this.configSvrHost.substring(0, this.configSvrHost.length() - 1);
        }
        this.appName = this.appName.trim();
        this.version = this.version.trim();
        this.env = this.env.trim();
    }


    public static ConfigSvrConfig getInstance() {
        return instance;
    }


    public String getConfigSvrHost() {
        return this.configSvrHost;
    }


    public String getAppName() {
        return this.appName;
    }


    public String getVersion() {
        return this.version;
    }


    public String getEnv() {
        return this.env;
    }


    public boolean isEnable() {
        return this.isEnable;
    }
}
